import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:news_flutter/models/video_model.dart';
import 'package:news_flutter/utils/http_request_util.dart';
import 'package:news_flutter/widgets/custom/my_appbar_widget.dart';
import 'package:news_flutter/widgets/custom/refresh_tableview_widget.dart';
import 'package:news_flutter/widgets/videos/video_item_widget.dart';

class VideoListPage extends StatefulWidget{

  @override
  _VideoListPageState createState() => _VideoListPageState();
}

class _VideoListPageState extends State<VideoListPage>  with AutomaticKeepAliveClientMixin {
@override
// TODO: implement wantKeepAlive
bool get wantKeepAlive => true;
  List <VideoModel> _list =[];
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _loadVideos();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MyAppBar(
        title: "抖音视频榜",
        myAppBarStyle: MyAppBarStyle.WHITE,
        actions: <Widget>[
          //搜索
          Container(
            width: 44,
            child: IconButton(
              icon: Icon(Icons.search),
              padding: EdgeInsets.zero,
              onPressed: () {
              },
            ),
          ),
        ],
      ),
      body: RefreshTableView(
        itemBuilder: (context,index){
          return VideoItem(videoModel: _list[index],);
        },
        itemCount: _list.length,
      ),
    );
  }
  //获取热搜列表
  void _loadVideos() {
    print("_loadVideos");
    HttpRequestUtil().get("txapi/dyvideohot/index", param: {}).then((value) {
      List newslist = value["newslist"];
      List<VideoModel> list =
      newslist.map((e) => VideoModel.fromJsonMap(e)).toList();
      setState(() {
        _list = list;
      });
    });
  }
}
